package com.knowledge.serve.service.impl;

import com.knowledge.db.mapper.UploadFileMapper;
import com.knowledge.model.pojo.UploadFile;
import com.knowledge.serve.service.UploadFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class UploadFileServiceImpl implements UploadFileService {
    @Autowired
    private UploadFileMapper uploadFileMapper;

    /**
     * 通过md5查询文件信息
     * @param md5
     * @return
     */
    @Override
    public Integer getFileByMd5(String md5) {

        return uploadFileMapper.getByMd5(md5);
    }

    /**
     * @desc 上传成功的文件添加到数据库中
     * @param fileMd5
     * @param targetFileName
     */
    @Override
    public void addFileRecord(String fileMd5, String targetFileName) {
        UploadFile uploadFile = new UploadFile();
        uploadFile.setFileMd5(fileMd5);
        uploadFile.setTargetFile(targetFileName);
        uploadFile.setCreateTime(LocalDateTime.now());
        uploadFile.setUpdateTime(LocalDateTime.now());

        uploadFileMapper.addFIleRecord(uploadFile);
    }
}
